package org.ph.share.lock.test.thread2;

import lombok.extern.slf4j.Slf4j;

import java.util.concurrent.locks.LockSupport;

/**
 * 实现俩个线程，先打印2再打印1
 * 方法1：synchronized关键字、wait()、notify() {@link Thread12}
 * 方法2：ReentrantLock、await、signal {@link Thread13}
 * 方法3：park与unpark (通行证策略){@link Thread14}
 * 方法1与方法2相似
 *
 * @author Hush.
 * @since 2023/5/18 12:53
 */
@Slf4j
public class Thread14 {
    public static void main(String[] args) {
        Thread thread1 = new Thread(() -> {
            LockSupport.park();
            log.info("1");
        }, "t-1");
        thread1.start();

        Thread thread2 = new Thread(() -> {
            log.info("2");
            LockSupport.unpark(thread1);
        }, "t2");
        thread2.start();

    }
}
